package com.springboot.frame.oauth.server.security.hadler;//package com.springboot.frame.oauth.server.security.hadler;

import com.springboot.frame.oauth.server.utils.ResponseUtils;
import com.springboot.frame.oauth.server.utils.RestResult;
import lombok.extern.slf4j.Slf4j;
import org.springframework.security.core.Authentication;
import org.springframework.security.web.authentication.logout.LogoutSuccessHandler;
import org.springframework.stereotype.Component;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * 用户登出时的拦截
 */
@Component
@Slf4j
public class SecurityLogoutSuccessHandler implements LogoutSuccessHandler {

    @Override
    public void onLogoutSuccess(HttpServletRequest request, HttpServletResponse response, Authentication authentication) {
        // 清除登录的session
        request.getSession().invalidate();
        log.info("退出成功");
        // JSON 格式的返回
        ResponseUtils.renderSuccessJson(request, response, new RestResult(200, "退出成功"));
    }
}
